import { createRouter, createWebHistory } from 'vue-router'
import Layout from '@/layouts/index.vue'

// 路由配置
export const routes = [
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        name: 'Dashboard',
        component: () => import('@/views/dashboard/index.vue'),
        meta: { title: '首页', icon: 'HomeFilled', affix: true }
      }
    ]
  },
  {
    path: '/topo',
    component: Layout,
    children: [
      {
        path: 'opt',
        name: 'Opt',
        component: () => import('@/views/topo/index.vue'),
        meta: { title: '拓扑图', icon: 'Map' }
      }
    ]
  },
  {
    path: '/:pathMatch(.*)*',
    name: 'NotFound',
    component: () => import('@/views/NotFound.vue'),
    meta: {
      title: '404', hidden: true
    },
  },
]

// 创建路由实例
const router = createRouter({
  history: createWebHistory(),
  routes,
})

// 路由前置守卫
router.beforeEach((to, from, next) => {
  // 设置页面标题
  document.title = to.meta.title || 'xxxx'
  next()
})

export default router 